package com.atme.inform.controller;

import com.atme.inform.dto.MailVo;
import com.atme.inform.service.impl.MailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/mail")
public class MailController {
    @Autowired
    private MailServiceImpl mailService;


    @GetMapping("/")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("mail/sendMail");
        mv.addObject("from", mailService.getMailSendFrom());
        return mv;
    }

    @PostMapping("/send")
    public MailVo sendMail(MailVo mailVo, MultipartFile[] files) {
        mailVo.setMultipartFiles(files);
        return mailService.sendMail(mailVo);
    }

        /**
         * 实现http接口发送短信 test
         * @param mailVo
         * @return
         */
        @PostMapping("/sendTest")
        public MailVo sendMailTest (@RequestBody MailVo mailVo){

            System.out.println("mail");
            return mailService.sendMail(mailVo);
        }

}